/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.koller.million.card.frame.item;

import de.koller.million.card.engine.item.Item;
import de.koller.million.card.engine.item.ItemProperty;
import java.awt.Color;

/**
 *
 * @author User
 */
public class ItemToolTip extends javax.swing.JFrame {

	public static final ItemToolTip SINGLE = new ItemToolTip();
	
	private Item item = null;
	
	/**
	 * Creates new form ItemToolTip
	 */
	public ItemToolTip() {
		initComponents();
	}

	public Item getItem() {
		return item;
	}

	public void showItem( Item item ) {
		this.item = item;
		
		if( item == null )
			return;
		
		this.damage.setForeground( item.getQualityColor() );
		this.damage.setText( Math.round( item.getDamage() ) + "" );
		this.ilvl.setText( "ilvl " + item.getIlvl() );
		this.slot.setText( item.getSlot().displayName );
		
		String p = "<html>";
		for( ItemProperty i : item.getProperties().keySet() ) {
			double pv = item.getPropertyValue( i );
			
			if( i.isPercent )
				p += "+" + pv + "% " + i.statname + "<br>";
			else
				p += "+" + Math.round( pv ) + " " + i.statname + "<br>";
		}
		p += "</html>";
		properties.setText( p );
		
		this.pack();
		this.setVisible( true );
	}

	public void unshow() {
		this.setVisible( false );
	}
	
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings( "unchecked" )
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        damage = new javax.swing.JLabel();
        ilvl = new javax.swing.JLabel();
        slot = new javax.swing.JLabel();
        properties = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setAlwaysOnTop(true);
        setAutoRequestFocus(false);
        setBackground(new java.awt.Color(0, 0, 0));
        setFocusable(false);
        setFocusableWindowState(false);
        setType(java.awt.Window.Type.POPUP);
        setUndecorated(true);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setForeground(new java.awt.Color(255, 255, 255));

        damage.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        damage.setForeground(new java.awt.Color(102, 255, 255));
        damage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        damage.setText("???");

        ilvl.setForeground(new java.awt.Color(255, 255, 255));
        ilvl.setText("ilvl ??");

        slot.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        slot.setForeground(new java.awt.Color(255, 255, 255));
        slot.setText("Slot ?");

        properties.setForeground(new java.awt.Color(255, 255, 255));
        properties.setText("+? ???");
        properties.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        properties.setMaximumSize(new java.awt.Dimension(31, 200));
        properties.setMinimumSize(new java.awt.Dimension(31, 1));
        properties.setName("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(ilvl))
                    .addComponent(damage, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(slot)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(properties, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(slot)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(damage)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(properties, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ilvl)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void formMouseExited( java.awt.event.MouseEvent evt ) {//GEN-FIRST:event_formMouseExited
		this.setVisible( false );
	}//GEN-LAST:event_formMouseExited

	/**
	 * @param args the command line arguments
	 */
	public static void main( String args[] ) {
		/*
		 * Set the Nimbus look and feel
		 */
		//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
		 * If Nimbus (introduced in Java SE 6) is not available, stay with the
		 * default look and feel. For details see
		 * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
		 */
		try {
			for( javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels() ) {
				if( "Nimbus".equals( info.getName() ) ) {
					javax.swing.UIManager.setLookAndFeel( info.getClassName() );
					break;
				}
			}
		} catch ( ClassNotFoundException ex ) {
			java.util.logging.Logger.getLogger( ItemToolTip.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
		} catch ( InstantiationException ex ) {
			java.util.logging.Logger.getLogger( ItemToolTip.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
		} catch ( IllegalAccessException ex ) {
			java.util.logging.Logger.getLogger( ItemToolTip.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
		} catch ( javax.swing.UnsupportedLookAndFeelException ex ) {
			java.util.logging.Logger.getLogger( ItemToolTip.class.getName() ).log( java.util.logging.Level.SEVERE, null, ex );
		}
		//</editor-fold>

		/*
		 * Create and display the form
		 */
		java.awt.EventQueue.invokeLater( new Runnable() {

			public void run() {
				new ItemToolTip().setVisible( true );
			}
		} );
	}
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel damage;
    private javax.swing.JLabel ilvl;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel properties;
    private javax.swing.JLabel slot;
    // End of variables declaration//GEN-END:variables
}
